package com.example.pc.http;

import android.content.Context;
import android.util.Log;

import com.example.pc.updata.DaTi.LoginActivity;
import com.example.pc.updata.MyApplication;
import com.example.pc.utils.JSONUtils;
import com.example.pc.utils.SpfUtils;

import java.util.HashMap;
import java.util.Map;


/**
 * Created by 他的猫 on 2017/5/10.
 */

public class API {


    /**
     * 数据列表查询
     *
     * @param
     * @param handler
     */
    public static void DiBengTJ(
            String startDate,
            String endDate, String water_zhanid, Okhttp.Objectcallback handler) {
        Map<String, String> map = new HashMap<>();

        map.put("startDate", startDate);
        map.put("endDate", endDate);
        map.put("water_zhanid", water_zhanid);
        String jg2 = JSONUtils.mapToJson(map);
        Log.e("API", "数据列表查询" + jg2);
        Log.e("API2", getBase() + "TCP_BB/Devices/querylist");
        Okhttp.post(getBase() + "TCP_Water/Devices/querylist", map, handler);

    }

    public static String getBase() {
        String ip = (String) SpfUtils.get(MyApplication.getInstance(), "ip", "192.168.43.1");
        String url = "http://" + ip + ":8080/";
        return url;
    }


    /**
     * 登录
     *
     * @param user_account
     * @param user_password
     * @param handler
     */
    public static void login(
            String user_account,
            String user_password, Okhttp.Objectcallback handler) {
        Map<String, String> map = new HashMap<>();

        map.put("user_account", user_account);
        map.put("user_password", user_password);

        String jg2 = JSONUtils.mapToJson(map);
        Log.e("API", "登录" + jg2);
        Log.e("API2", getBase() + "DT_2019/Uesr/login");
        Okhttp.post(getBase() + "DT_2019/Uesr/login", map, handler);

    }

    /**
     * 更改密码
     *
     * @param user_account
     * @param user_password
     * @param handler
     */
    public static void genggai(
            String user_account,
            String newuser_password, String question, Okhttp.Objectcallback handler) {
        Map<String, String> map = new HashMap<>();

        map.put("user_account", user_account);
        map.put("newuser_password", newuser_password);
        map.put("question", question);
        String jg2 = JSONUtils.mapToJson(map);
        Log.e("API", "登录" + jg2);
        Log.e("API2", getBase() + "DT_2019/Uesr/Change_Password");
        Okhttp.post(getBase() + "DT_2019/Uesr/Change_Password", map, handler);

    }

    /**
     * 注册
     *
     * @param user_account
     * @param user_password
     * @param handler
     */
    public static void register(
            String user_account,
            String user_password, String question, Okhttp.Objectcallback handler) {
        Map<String, String> map = new HashMap<>();

        map.put("user_account", user_account);
        map.put("user_password", user_password);
        map.put("user_name", "");
        map.put("question", question);
        String jg2 = JSONUtils.mapToJson(map);
        Log.e("API", "登录" + jg2);
        Log.e("API2", getBase() + "DT_2019/Uesr/register");
        Okhttp.post(getBase() + "DT_2019/Uesr/register", map, handler);

    }

    /**
     * 反馈
     *
     * @param title
     * @param comment
     * @param handler
     */
    public static void comments(Context context,
                                String title,
                                String comment, Okhttp.Objectcallback handler) {
        String NAME = (String) SpfUtils.get(context, "neme", "xx");
        Map<String, String> map = new HashMap<>();

        map.put("title", title);
        map.put("comment", comment);
        map.put("user", NAME);
        String jg2 = JSONUtils.mapToJson(map);
        Log.e("API", "反馈" + jg2);
        Log.e("API2", getBase() + "DT_2019/comments/addcomment");
        Okhttp.post(getBase() + "DT_2019/comments/addcomment", map, handler);

    }

    /**
     * cha反馈
     *
     * @param handler
     */
    public static void getcomments(
            Okhttp.Objectcallback handler) {


        Okhttp.post(getBase() + "DT_2019/comments/getcomments", null, handler);

    }


    public static void gettimus(
            Okhttp.Objectcallback handler) {


        Okhttp.post(getBase() + "DT_2019/timu/gettimus", null, handler);

    }


    /**
     * 删除题目
     *
     * @param id
     * @param handler
     */
    public static void timudetel(
            String id,
            Okhttp.Objectcallback handler) {
        Map<String, String> map = new HashMap<>();

        map.put("id", id);

        String jg2 = JSONUtils.mapToJson(map);
        Log.e("API", "s" + jg2);
        Log.e("API2", getBase() + "DT_2019/timu/deteltimu");
        Okhttp.post(getBase() + "DT_2019/timu/deteltimu", map, handler);

    }

    /**
     * 修改题目
     *
     * @param id
     * @param handler
     */
    public static void updatatimu(
            String id,
            String tm,
            String a,
            String b,
            String c,
            String d,
            String zq,
            Okhttp.Objectcallback handler) {
        Map<String, String> map = new HashMap<>();

        map.put("id", id);
        map.put("tm", tm);
        map.put("a", a);
        map.put("b", b);
        map.put("c", c);
        map.put("d", d);
        map.put("zq", zq);


        String jg2 = JSONUtils.mapToJson(map);
        Log.e("API", "s" + jg2);
        Log.e("API2", getBase() + "DT_2019/timu/updatatimu");
        Okhttp.post(getBase() + "DT_2019/timu/updatatimu", map, handler);

    }


    /**
     * zengjia题目
     *
     * @param
     * @param handler
     */
    public static void addtimu(

            String tm,
            String a,
            String b,
            String c,
            String d,
            String zq,
            Okhttp.Objectcallback handler) {
        Map<String, String> map = new HashMap<>();


        map.put("tm", tm);
        map.put("a", a);
        map.put("b", b);
        map.put("c", c);
        map.put("d", d);
        map.put("zq", zq);


        String jg2 = JSONUtils.mapToJson(map);
        Log.e("API", "s" + jg2);
        Log.e("API2", getBase() + "DT_2019/timu/addtimu");
        Okhttp.post(getBase() + "DT_2019/timu/addtimu", map, handler);

    }


    /**
     * 增加成绩
     *
     * @param
     * @param handler
     */
    public static void addchengji(Context context, String chengji,


                                  Okhttp.Objectcallback handler) {
        String NAME = (String) SpfUtils.get(context, "neme", "xx");
        Map<String, String> map = new HashMap<>();


        map.put("name", NAME);
        map.put("chengji", chengji);


        String jg2 = JSONUtils.mapToJson(map);
        Log.e("API", "s" + jg2);
        Log.e("API2", getBase() + "DT_2019/chengji/addchengji");
        Okhttp.post(getBase() + "DT_2019/chengji/addchengji", map, handler);

    }

    /**
     * 获得学生列表
     *
     * @param handler
     */
    public static void getChengJi(
            Okhttp.Objectcallback handler) {

        Okhttp.post(getBase() + "DT_2019/chengji/getchengjis", null, handler);

    }


    /**
     * 获得课程列表
     *
     * @param handler
     */
    public static void getmyCurriculums(Context context,
                                        Okhttp.Objectcallback handler) {
        String NAME = (String) SpfUtils.get(context, "neme", "xx");
        Map<String, String> map = new HashMap<>();


        map.put("name", NAME);

        Okhttp.post(getBase() + "DT_2019/chengji/getchengjibyname", map, handler);

    }


    /**
     * 反馈
     *
     * @param
     * @param
     * @param handler
     */
    public static void addjianyi(Context context,
                                 String id,
                                 String jianyi, Okhttp.Objectcallback handler) {

        Map<String, String> map = new HashMap<>();

        map.put("id", id);
        map.put("jianyi", jianyi);

        String jg2 = JSONUtils.mapToJson(map);
        Log.e("API", "反馈" + jg2);
        Log.e("API2", getBase() + "DT_2019/comments/addcomment");
        Okhttp.post(getBase() + "DT_2019/chengji/addjianyi", map, handler);

    }


    /**
     * 用户管理
     *
     * @param
     * @param
     * @param handler
     */
    public static void yonghuguanli(
            Okhttp.Objectcallback handler) {


        Okhttp.post(getBase() + "DT_2019/Uesr/QueryALL", null, handler);

    }


    //   删除用户
    public static void shanchu(
            String user_id,
            Okhttp.Objectcallback handler) {

        Map<String, String> map = new HashMap<>();

        map.put("user_id", user_id);


        Okhttp.post(getBase() + "DT_2019/Uesr/deleteUser", map, handler);

    }


    /**
     * 答错题目
     *
     * @param
     * @param handler
     */
    public static void addctimu(String tm,

                                String zq,
                                String cw,
                                String jx,
                                String user_uid,
                                Okhttp.Objectcallback handler) {
        Map<String, String> map = new HashMap<>();


        map.put("tm", tm);
        map.put("zq", zq);
        map.put("cw", cw);
        map.put("jx", jx);
        map.put("user_uid", user_uid);


        String jg2 = JSONUtils.mapToJson(map);
        Log.e("API", "s" + jg2);
        Log.e("API2", getBase() + "DT_2019/ctimu/addctimu");
        Okhttp.post(getBase() + "DT_2019/ctimu/addctimu", map, handler);

    }

    //   我的错题
    public static void wodecuoti(
            String user_uid,
            Okhttp.Objectcallback handler) {

        Map<String, String> map = new HashMap<>();

        map.put("user_uid", user_uid);


        Okhttp.post(getBase() + "DT_2019/ctimu/getctimus", map, handler);

    }
}
